home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10998 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  69 lines

  1. Path: news.ner.bbnplanet.net!forest!groy
  2. From: groy@forest.drew.edu (I can't think of a nickname)
  3. Newsgroups: comp.lang.c
  4. Subject: HELP!!! -very important-- #3
  5. Message-ID: <1996Mar21.001800.138165@forest>
  6. Date: 21 Mar 96 00:18:00 EST
  7. Organization: Drew University
  8.  
  9. This is the last one (for a while nayway.. ) I promise.. ;)
  10. I am trying to write a program that will take in any input.. and count up 
  11. the numbers of characters... words and lines... it just doesn't want to 
  12. work... help??
  13.  
  14. #include<stdio.h>
  15. #include<ctype.h>
  16.  
  17. int main()  {
  18.    int words = 0; /* number of words */
  19.    int lines = 0; /* number of lines */
  20.    int characters = 0; /* number of characters */
  21.    char input; /* the area of input */
  22.    int check_letter(char input); /* function that will check characters */
  23.    int check_lines(char input); /* function that will check lines */
  24.    int whitespace = 1;
  25.  
  26.  
  27.    printf("type in any group of words, lines, characters that you wish");
  28.    printf("\nthen the computer will display the amount of words, lines");
  29.    printf("\nand characters (ignoring any white-space) that you may\n");
  30.    printf("type in.   <<press cntrl-d when done>> \n");
  31.  
  32.    while ((scanf("%c",&input)) != EOF)
  33.      {
  34.       characters += isalnum(input);
  35.       lines = check_lines(input) + lines;
  36.       if (isspace(input)) {
  37.            whitespace++;
  38.            }
  39.       else if (isalnum(input) && (whitespace > 0)) {
  40.                whitespace = 0;
  41.                words++;  }
  42.      }
  43.  
  44.    printf("the number of lines is: %i\n", lines);
  45.    printf("the number of words is: %i\n", words);
  46.    printf("the number of characters is: %i\n", characters);
  47.  
  48. }  /* end of main */
  49.  
  50. int check_letter(char input) {
  51.        return isalnum(input);
  52.        } /*end of check_letter */
  53. int check_lines(char input) {
  54.        return iscntrl(input);;
  55.        } /* end of check_lines */
  56.  
  57.  
  58.  
  59. I just noticed something... the { and } are the forward brackets and 
  60. reverse brackets.. I deleted them from the last post... if they look 
  61. correct to you then fine... if not.. I hope you can read how the last post 
  62. went... thecomments should help..... aahhhhhhh i am breaking doen here... 
  63. please help
  64.  
  65.  
  66.  
  67. Greg Roy
  68. groy@drew.edu
  69.